package com.singbon.controller;
import com.alibaba.fastjson.JSON;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * The type Client controller.
 * @author xxx
 */
@RestController
public class ClientController {
  /**
   * Normal string.
   * http://localhost:8084/normal
   * @return the string
   */
  @GetMapping("/normal")
  @PreAuthorize("hasAuthority('ROLE_ADMIN')")
  public String normal() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    String name = authentication.getName();
    Object[] authoritiesObj = authentication.getAuthorities().toArray();
    return "normal:管理员:" + name + "\n权限:" + JSON.toJSONString(authoritiesObj);
  }
  /**
   * Medium string.
   *
   * @return the string
   */
  @GetMapping("/medium")
  @PreAuthorize("hasAuthority('ROLE_USER')")
  public String medium() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    String name = authentication.getName();
    Object[] authoritiesObj = authentication.getAuthorities().toArray();
    return "medium:管理员:" + name + "\n权限:" + JSON.toJSONString(authoritiesObj);
  }
  /**
   * Admin string.
   *
   * @return the string
   */
  @GetMapping("/admin")
  @PreAuthorize("hasAuthority('ROLE_SYSTEMMANAGER')")
  public String admin() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    String name = authentication.getName();
    Object[] authoritiesObj = authentication.getAuthorities().toArray();
    return "admin:管理员:" + name + "\n权限:" + JSON.toJSONString(authoritiesObj);
  }
}

